import storage from "../../utils/storage";

const filter = {
	state: {
		brand_id: storage.get("xunche-filter-brand_id") || '',
		brand_name: storage.get("xunche-filter-brandname") || '',
		series_id: storage.get("xunche-filter-series_id") || '',
		series_name: storage.get("xunche-filter-seriesname") || '',
		car_id: storage.get("xunche-filter-car_id") || '',
		car_name: storage.get("xunche-filter-carname") || '',
		sort: storage.get("xunche-filter-sort") || '',
		/* 地区 */
		province_id: storage.get("xunche-filter-province_id") || '',
		province_name: storage.get("xunche-filter-provincename") || '全国', // 省份名称
		city_id: storage.get("xunche-filter-city_id") || '',
		city_name: storage.get("xunche-filter-cityname") || '', // 城市名称
		// 价格
		price_start: storage.get("xunche-filter-price_start") || 0,
		price_end: storage.get("xunche-filter-price_end") || 0,
		// 车龄
		car_age_start: storage.get("xunche-filter-car_age_start") || 0,
		car_age_end: storage.get("xunche-filter-car_age_end") || 0,
		// 行驶里程
		mileage_start: storage.get("xunche-filter-mileage_start") || 0,
		mileage_end: storage.get("xunche-filter-mileage_end") || 0,
		// 变速箱
		geartype: storage.get("xunche-filter-geartype") || 0,
		// 动力类型
		type: storage.get("xunche-filter-type") || 0,
		// 排量
		displacement_start: storage.get("xunche-filter-displacement") || '',
		displacement_end: storage.get("xunche-filter-displacement") || '',
		// 车身颜色
		color: storage.get("xunche-filter-color") || ''
	},
	mutations: {
		SET_BRAND(state, data) {
			state.brand_id = data.brand_id
			state.series_id = data.series_id
			state.car_id = data.car_id
			storage.set("xunche-filter-brand_id", data.brand_id)
			storage.set("xunche-filter-brandname", data.brand_name)
			storage.set("xunche-filter-series_id", data.series_id)
			storage.set("xunche-filter-seriesname", data.series_name)
			storage.set("xunche-filter-car_id", data.car_id)
			storage.set("xunche-filter-carname", data.car_name)
		},
		SET_SORT(state, sort) {
			state.sort = sort;
			storage.set("xunche-filter-sort", sort)
		},
		SET_ADDRESS(state, addr) {
			state.province_id = addr.province_id;
			state.province_name = addr.province_name;
			state.city_id = addr.city_id;
			state.city_name = addr.city_name;
			storage.set("xunche-filter-province_id", addr.province_id)
			storage.set("xunche-filter-city_id", addr.city_id)
			storage.set("xunche-filter-provincename", addr.province_name)
			storage.set("xunche-filter-cityname", addr.city_name)
		},
		SET_PRICE(state, price) {
			state.price_start = price.price_start;
			state.price_end = price.price_end;
			storage.set("xunche-filter-price_start", price.price_start)
			storage.set("xunche-filter-price_end", price.price_end)
		},
		SET_CAR_AGE(state, age) {
			state.car_age_start = age.car_age_start;
			state.car_age_end = age.car_age_end;
			storage.set("xunche-filter-car_age_start", age.car_age_start)
			storage.set("xunche-filter-car_age_end", age.car_age_end)
		},
		SET_MILEAGE(state, mileage) {
			state.mileage_start = mileage.mileage_start;
			state.mileage_end = mileage.mileage_end;
			storage.set("xunche-filter-mileage_start", mileage.mileage_start)
			storage.set("xunche-filter-mileage_end", mileage.mileage_end)
		},
		SET_GEARTYPE(state, gearType) {
			state.geartype = gearType;
			storage.set("xunche-filter-geartype", gearType)
		},
		SET_TYPE(state, type) {
			state.type = type;
			storage.set("xunche-filter-type", type)
		},
		SET_DISPLACEMENT(state, displacement) {
			state.displacement_start = displacement.displacement_start;
			state.displacement_end = displacement.displacement_end;
			storage.set("xunche-filter-displacement", displacement.displacement_start)
			storage.set("xunche-filter-displacement", displacement.displacement_end)
		},
		SET_COLOR(state, color) {
			state.color = color;
			storage.set("xunche-filter-color", color)
		},
	},
}

export default filter